<?php
 include "counter.php";

  if (!$distribution) {
    $distribution = 'All';
  }
  if ($distribution == 'All') {
     $total = dbcount("machines");
  } else {
     $total = dbcount("machines", "distribution='$distribution'");
  }

?>
<?php pagehead("Distribution of usage of $distribution") ?>
<BODY bgcolor="white">
<?php pagetop() ?>
<h1>Linux regions where <?php echo $distribution ?> is used</h1>
Out of a total of <?php echo $total ?> machines registered:

<table border>
<?php

if ($distribution == 'All') {
  $query = mysql_query("select count(*) as c, country from machines
       group by country order by c
       desc");
} else {
  $query = mysql_query("select count(*) as c, country from machines
       where distribution = '$distribution' group by country order by c
       desc");
}
if (!$query) {
     print('MySQL error: '. mysql_errno() .':'. mysql_error());
      die('Query for countries failed');
}


while ($arr = mysql_fetch_array($query)) {
   printf("<tr><td>%5d<td>%5.1f%%<td>%s\n",
        $arr["c"], $arr["c"] * 100 / $total, 
	"<a href=\"distbyregion.php?region=" . $arr["country"]
	. "\">" . $arr["country"] . "</a>");
}
?>
</table>



<?php pagebottom() ?>
</body>
</html>


